import { http } from "@/utils/http";

/** 设备分组配置模型定义 */
export type DeviceGroupConfigModel = {
  id: number;
  deviceGroupId: number;
  groupName: string;
  configKey: string;
  configValue: string;
  remark: string;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取设备分组配置列表 */
export const getDeviceGroupConfigListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<DeviceGroupConfigModel>>>(
    "get",
    "/device-group-config/page-list",
    { params: data }
  );
};

/** 新增设备分组配置 */
export const addDeviceGroupConfigApi = (data: Partial<DeviceGroupConfigModel>) => {
  return http.request<Resp<null>>("post", "/device-group-config", { data });
};

/** 更新设备分组配置 */
export const updateDeviceGroupConfigApi = (id: number, data: Partial<DeviceGroupConfigModel>) => {
  return http.request<Resp<null>>("put", `/device-group-config/${id}`, { data });
};

/** 删除设备分组配置 */
export const deleteDeviceGroupConfigApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/device-group-config/${id}`);
};

/** 根据ID获取设备分组配置详情 */
export const getDeviceGroupConfigByIdApi = (id: number) => {
  return http.request<Resp<{
    info: DeviceGroupConfigModel
  }>>('get', '/device-group-config/getOne', {
    params: { id }
  });
};

/** 获取设备分组配置选项列表 */
export const getDeviceGroupConfigOptionsApi = (params?: { deviceGroupId?: number, groupName?: string }) => {
  return http.request<Resp<{
    options: Array<{
      label: string;
      val: string | number;
    }>
  }>>('get', '/device-group-config/getOptions', { params });
};

/** 获取设备分组配置组 */
export const getDeviceGroupGroupConfigsApi = (params: {
  deviceGroupId: number;
  groupName: string;
}) => {
  return http.request<Resp<{
    configs: Array<{
      configKey: string;
      configValue: string;
      configDesc: string;
    }>;
    updatedAt: string;
  }>>(
    'get',
    '/device-group-config/get-device-group-group-configs',
    { params }
  );
};

/** 保存设备分组配置组 */
export const setDeviceGroupGroupConfigsApi = (data: {
  deviceGroupId: number;
  groupName: string;
  configs: Array<{
    configKey: string;
    configValue: string;
    configDesc?: string;
  }>
}) => {
  return http.request<Resp<null>>(
    'post',
    '/device-group-config/set-device-group-group-configs',
    { data }
  );
};
